package com.wanmait.hr.service.Impl;

import com.wanmait.hr.mapper.ContractMapper;
import com.wanmait.hr.service.ContractService;
import com.wanmait.hr.vo.Contract;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@Service
public class ContractServiceImpl implements ContractService {

    @Resource
    private ContractMapper contractMapper;

    @Override
    public void addContract(String time,Contract c) {//添加档案---陈正儒
        String timex[]=time.split(" - ");
        String a=timex[0];
        String y=timex[1];
        String times []=a.split("/");
        String b=times[2]+"-"+times[0]+"-"+times[1];
        String t[]=y.split("/");
        String d=t[2]+"-"+t[0]+"-"+t[1];
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        format.setLenient(false);
        //要转换字符串 str_test
        try {
            Timestamp ts = new Timestamp(format.parse(b).getTime());
            Timestamp ts1=new Timestamp(format.parse(d).getTime());
            c.setStartTime(ts);
            c.setEndTime(ts1);
            contractMapper.addContract(c);
        } catch (ParseException e) {

            e.printStackTrace();
        }


    }

    @Override
    public Contract checkContract(int id) {//查看个人合同--陈正儒
        return contractMapper.checkContract(id);
    }
}
